<template>

  <!-- 添加或修改盘点计划对话框 -->
  <el-dialog :title="title" v-if="open" v-model="open" width="600px" append-to-body>
    <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" @click="handleAdd">添加 </el-button>
          </el-col>
          
        </el-row>
    <el-table v-loading="loading" :data="dataSource">
        <el-table-column label="价格名称" align="center" prop="dictLabel">
          <template #default="scope">
            <span
              v-if="(scope.row.listClass === '' || scope.row.listClass === 'default') && (scope.row.cssClass === '' || scope.row.cssClass == null)">{{
                scope.row.dictLabel }}</span>
            <el-tag v-else
              :type="scope.row.listClass === 'primary' || scope.row.listClass === 'default' ? 'primary' : scope.row.listClass"
              :class="scope.row.cssClass">{{ scope.row.dictLabel }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button v-hasPermi="['system:dict:edit']" link type="primary" icon="Edit"
                @click="handleUpdate(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button v-hasPermi="['system:dict:remove']" link type="primary" icon="Delete"
                @click="handleDelete(scope.row.dictCode)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      
      <customPriceForm ref="modelForm" @ok="addOk"></customPriceForm>
    <!-- 添加或修改参数配置对话框 -->
    <el-dialog v-model="dialog.visible" :title="dialog.title" width="500px" append-to-body>
      <el-form ref="dataFormRef" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="价格名称" prop="dictLabel">
          <el-input v-model="form.dictLabel" placeholder="请输入价格名称" />
        </el-form-item>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="dialog.visible = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          
          <el-button type="primary" @click="ok">确 定</el-button>
        </div>
      </template>
  </el-dialog>
</template>

<script>
import listMixin from '@/mixins/listMixin';
import { updateData } from '@/api/system/dict/data';
import customPriceForm from './customPriceForm.vue';
import { refreshCache } from '@/api/goods/goods';
export default {
  name: "addForm",
  mixins: [listMixin],
  components: {
    customPriceForm
  },
  data() {
    return {
      open: false,
      title: "自定义单位价格",
      form: {},
      loading: false,
      dialog:{
        visible:false,
        title:'编辑自定义单位价格'
      },
      urls:{
        list:'/system/dict/data/list',
        delete:'/system/dict/data'
      },
      queryParams:{
        dictType:'mx_material_price'
      },
      rules: {
        dictLabel: [
          { required: true, message: "价格名称不能为空", trigger: "blur" }
        ],
      },
    }
  },
  created() {
  },
  methods: {
    show() {
      this.open = true;
      this.getList();
    },
    cancel() {
      console.log('666',666);
      this.open = false;

    },
    addOk(){
      this.getList()
      this.$emit('change')
    },
    handleDelete(ids) {
            this.$modal.confirm('确定删除？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                request({
                    url: this.urls.delete + '/' + ids,
                    method: 'delete'
                }).then(res => {
                    if (res.code == 200) {
                        this.$modal.msgSuccess('删除成功')
                        this.$emit('change')
                        this.getList()
                    } else {
                        this.$modal.msgError(res.msg)
                    }
                });
            }).catch(() => { });
        },
    handleUpdate(row){
      this.form = Object.assign({}, row);
      this.dialog.title="修改价格";
      this.dialog.visible=true;
    },
    listAfter(){
      this.dataSource = this.dataSource.filter(v=> v.dictSort > 60)
    },
    submitForm() {
      this.$refs.dataFormRef.validate((valid) => {
        if (valid) {
          updateData(this.form).then(res => {
            if (res.code == 200) {
              this.dialog.visible = false;
              this.$modal.msgSuccess("修改成功");
              this.$emit('change')
              this.getList();
            } else {
              this.$modal.msgError(res.msg)
            }
          }).catch(err => {
            this.loading = false;
          })
        } else {
          return false;
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped></style>